package edu.chinasoft.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.annotation.WebServlet;
import org.apache.log4j.Logger;

import edu.chinasoft.pojo.City;
import edu.chinasoft.pojo.Province;
import edu.chinasoft.service.ProvinceService;
import edu.chinasoft.service.ProvinceServiceImp;

/**
 *
 * @author mhao
 * @date 2020年2月12日:下午3:56:48
 * @version V1.0
 * @Description: 
*/
@WebServlet(name = "myFindCityByProcinceServlet", value = "/servlet/findcitybyprocinceservlet")
public class FindCityByProcinceServlet extends HttpServlet {
	private static Logger logger = Logger.getLogger(FindCityByProcinceServlet.class);
	private ProvinceService provinceService = new ProvinceServiceImp();
	/**
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug(" FindCityByProcinceServlet >doGet start.......");
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		logger.debug(" FindCityByProcinceServlet >doGet end.......");
	}

	/**
	 *
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug(" FindCityByProcinceServlet >doPost start.......");
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter writer = response.getWriter();
		String provinceID = request.getParameter("provinceID");
		Province province = new Province(provinceID);
		Province provinceResult = provinceService.findCityByProvince(province);
		writer.write("<?xml version='1.0' encoding='UTF-8'?>");
		writer.write("<root>");
		for(City city:provinceResult.getCitys()) {
			writer.write("<city value='"+city.getId()+"'>"+city.getCityName()+"</city>");
		}
		writer.write("</root>");
		writer.flush();
		writer.close();
		logger.debug(" FindCityByProcinceServlet >doPost end.......");
	}

}